package com.ktgj.pay.controller;

import com.ktgj.common.core.domain.R;
import com.ktgj.common.core.enums.EmHelper;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.customer.api.RemoteCustomerService;
import com.ktgj.customer.api.domain.BankCard;
import com.ktgj.customer.api.domain.BankPayInfo;
import com.ktgj.customer.api.domain.Customer;
import com.ktgj.pay.YeeBaoPay.YeeBaoResult;
import com.ktgj.pay.payUtil.YeeBaoPayUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@ControllerAdvice
@RestController
@RequestMapping("/bankPay")
public class YeeBaoController {

    @Autowired
    private YeeBaoPayUtil yeeBaoPayUtil;

//    /**
//     * 银行借记卡消费
//     * */
//    @PostMapping("/bankCreditSale")
//    public AjaxResult CreditSale(@RequestBody BankPayInfo bankPayInfo)
//    {
//        YeeBaoResult yeeBaoResult = yeeBaoPayUtil.DebitSale(bankPayInfo.getJsjOrderId(), bankPayInfo.getMoneyAmout(), bankPayInfo.getCustomer(), bankPayInfo.getCard(), null);
//        return AjaxResult.success(yeeBaoResult);
//    }

    /**
     * 银行借记卡消费
     * */
    @PostMapping("/bankDebitSale")
    public YeeBaoResult DebitSale(@RequestBody BankPayInfo bankPayInfo)
    {
        YeeBaoResult yeeBaoResult = yeeBaoPayUtil.DebitSale(bankPayInfo.getJsjOrderId(), bankPayInfo.getMoneyAmout(), bankPayInfo.getCustomer(), bankPayInfo.getCard(), null);
        return yeeBaoResult;
    }

//    /**
//     * 银行信用卡消费
//     * */
//    @PostMapping("/bankDebitSale")
//    public AjaxResult DebitSale(@RequestBody BankPayInfo bankPayInfo)
//    {
//        YeeBaoResult yeeBaoResult = yeeBaoPayUtil.CreditSale(bankPayInfo.getJsjOrderId(), bankPayInfo.getMoneyAmout(), bankPayInfo.getCustomer(), bankPayInfo.getCard(), null);
//        return AjaxResult.success(yeeBaoResult);
//    }

    /**
     * 银行信用卡消费
     * */
    @PostMapping("/bankCreditSale")
    public YeeBaoResult CreditSale(@RequestBody BankPayInfo bankPayInfo)
    {
        YeeBaoResult yeeBaoResult = yeeBaoPayUtil.CreditSale(bankPayInfo.getJsjOrderId(), bankPayInfo.getMoneyAmout(), bankPayInfo.getCustomer(), bankPayInfo.getCard(), null, bankPayInfo.getPayType());
        return yeeBaoResult;
    }

    /**
     * 银行卡借记卡退款
     * @param map
     * @return
     */
    @PostMapping("/bankDebitRefund")
    public YeeBaoResult bankDebitRefund(@RequestBody Map<String, String> map)
    {
        String jsjOrderId = map.get("jsjOrderId");
        String bankTrxId = map.get("bankTrxId");
        String moneyAmout = map.get("moneyAmout");
        YeeBaoResult yeeBaoResult = yeeBaoPayUtil.DebitRefund(jsjOrderId, bankTrxId,moneyAmout);
        return yeeBaoResult;
    }

    /**
     * 信用卡退款
     */
    @RequestMapping("/bankCreditRefund")
    public YeeBaoResult bankCreditRefund(@RequestBody Map<String, String> map)
    {
        String jsjOrderId = map.get("jsjOrderId");
        String bankTrxId = map.get("bankTrxId");
        String moneyAmout = map.get("moneyAmout");
        String payType = map.get("payType");
        YeeBaoResult yeeBaoResult = yeeBaoPayUtil.CreditRefund(jsjOrderId, bankTrxId,moneyAmout, payType);
        return yeeBaoResult;
    }

    /**
     * 信用卡预授权消费 todo 该方法未调通
     */
    public String AuthSale(String jsjOrderId, BankCard bankCard, Customer customer, String callBackUrl){
        return null;
    }

    /**
     * 信用卡预授权确认
     */
    public String AuthConConfirm(String yeeBaoTrxId, BigDecimal moneyAmout){
        return null;
    }

    /**
     * 信用卡预授权取消
     */
    public String AuthCancel(String yeeBaoTrxId){
        return null;
    }

    /**
     * 验证码确认消费
     */
    @PostMapping("/VerifySale")
    public YeeBaoResult VerifySale(@RequestBody Map<String, Object> map){
        String jsjOrderId = map.get("jsjOrderId").toString();
        String verifyCode = map.get("verifyCode").toString();

        YeeBaoResult yeeBaoResult = yeeBaoPayUtil.VerifySale(jsjOrderId, verifyCode);

        return yeeBaoResult;
    }

    /**
     * 订单验证码获取
     * @param jsjOrderId
     * @return
     */
    @PostMapping("/VerifyCodeReceive")
    public YeeBaoResult VerifyCodeReceive(@RequestBody String jsjOrderId){
        YeeBaoResult yeeBaoResult = yeeBaoPayUtil.VerifyCodeReceive(jsjOrderId);
        return yeeBaoResult;
    }

    /**
     * 订单信息查询
     * @return
     */
    @PostMapping("/bankQueryOrder")
    public AjaxResult QueryOrdDetail(@RequestBody Map<String, String> map)
    {
        String jsjOrderId = map.get("jsjOrderId");
        YeeBaoResult yeeBaoResult = yeeBaoPayUtil.QueryOrdDetail(jsjOrderId);
        return AjaxResult.success(yeeBaoResult);
    }
}

